<!DOCTYPE html>
<html lang="en">
<head>
    <title>Netty-SocketIO Demo</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.4.0/socket.io.js"></script>
    <meta charset="UTF-8">
</head>
<body>
<label for="message">输入消息：</label><input type="text" id="message" placeholder="输入消息">
<button onclick="sendMessage()">发送</button>
<div id="output"></div>

<script>
    // 连接服务器
    const socket = io('http://localhost:9092');

    // 监听服务端发过来的消息
    socket.on('message', (data) => {
        const div = document.createElement('div');
        div.textContent = data;
        document.getElementById('output').appendChild(div);
    });

    // 给socket-io服务端发送消息
    function sendMessage() {
        const input = document.getElementById('message');
        socket.emit('message', input.value);
        input.value = '';
    }

</script>
</body>
</html>